﻿using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using VIT.DataHelper.DataAccess;

namespace VIT.Business
{
    public class BLPage
    {
        #region Entities
        public string Id { get; set; }
        public string Image { get; set; }
        public string LanguageId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string Contents { get; set; }
        public string Tag { get; set; }

        SQLSupport sqlSupport = new SQLSupport();
        #endregion

        #region Constructor
        public BLPage(string id = "",
                        string languageId = "",
                        string image = "",
                        string title = "", 
                        string description = "",                        
                        string contents = "",
                        string tag = "")
        {
            this.Id = id;            
            this.LanguageId = languageId;         
            this.Title = title;
            this.Description = description;            
            this.Contents = contents;
            this.Tag = tag;
        }
        #endregion

        #region Methods
        public void GetSingle()
        {
            string strQuery = "select Id, Title, Image, Description, Contents, Tag from Page where LanguageId=@LanguageId and Id=@Id";
            SqlParameter Id = new SqlParameter("@Id", this.Id);
            SqlParameter LanguageId = new SqlParameter("@LanguageId", this.LanguageId);
            DataTable dt = sqlSupport.ExecuteDataset(false, strQuery, Id, LanguageId).Tables[0];

            if (dt.Rows.Count > 0)
            {                                
                this.Title = dt.Rows[0]["Title"].ToString();
                this.Image = dt.Rows[0]["Image"].ToString();
                this.Description = dt.Rows[0]["Description"].ToString();
                this.Contents = dt.Rows[0]["Contents"].ToString();
                this.Tag = dt.Rows[0]["Tag"].ToString();
            }            
            else this.Id = "";
        }        
        #endregion       
    }
}
